import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import javax.swing.event.*;
import java.lang.reflect.*;
import java.net.*;
import java.util.List;

class LoginS extends JFrame{
        Container contain;
        JPasswordField password;
        JTextField text1;
        JButton button1,button2,button3,button4;
        JLabel label1,label2,label3;
        JPanel panel1,panel2,panel3;
        String line;
        String id = "";
        String pass = "";
        //Student Login to connect in the Instructors machine.
        LoginS(){
        super(" Student Login ");

        contain = getContentPane();
        contain.setLayout(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        panel1 = new JPanel(null,true);
        label1 = new JLabel(" ID Number ");
        label1.setForeground(Color.black);
        label1.setToolTipText(" Your ID Number ");
        label1.setBounds(10,10,120,25);
        panel1.add(label1);

        text1 = new JTextField();
        text1.setEditable(true);
        text1.setBounds(100,10,120,25);
        panel1.add(text1);

        label2 = new JLabel("Password");
        label2.setForeground(Color.black);
        label2.setToolTipText("Example: IDNUMBER = 2122469 PASSWORD = 9642212");
        label2.setBounds(10,50,120,25);
        panel1.add(label2);

        password = new JPasswordField();
        password.setBounds(100,50,120,25);
        panel1.add(password);

        label3 = new JLabel();
        label3.setBounds(15,125,260,25);
        panel1.add(label3);

        button1 = new JButton("Ok");
        button1.setBounds(20,90,100,25);
        panel1.add(button1);

        button2 = new JButton("Cancel");
        button2.setBounds(130,90,100,25);
        panel1.add(button2);

        button3 = new JButton("Back");
        button3.setBounds(20,116,100,25);
        panel1.add(button3);

        button4 = new JButton("Clear");
        button4.setBounds(130,116,100,25);
        panel1.add(button4);

        Color r3 = new Color(122,145,201);
        panel1.setBounds(0,0,260,260);
        contain.add(panel1);
        // Reads the student Records.txt file
        try {
                BufferedReader br = new BufferedReader(new FileReader("StudentRecords.txt"));
        while ( ( line = br.readLine() ) != null ) {
            String [] tmp = line.split(",");
            id = tmp[0];
            pass = tmp[1];
        }
        } catch (Exception e) {
            e.printStackTrace();
        }


    button1.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
          try{
            StudentGUI2 s = new StudentGUI2();
            s.setVisible(false);
            dispose();
            s.setSize(800,600);
            }catch(Exception err){

            }
        }
    });

    button3.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            try{
            MemberType s=new MemberType();
                        s.setVisible(true);
            s.setSize(270,180);
            dispose();
            s.setLocation(500,250);
            }catch(Exception sam){

            }
        }
    });


    button2.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            System.exit(0);
        }
    });

    button4.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                        text1.setText("");
                password.setText("");
        }
    });

}
}